package com.itheima.hello.缓冲流;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class 读写 {
    public static void main(String[] args) {
        try(BufferedReader br = new BufferedReader(new FileReader("helloworld-app\\src\\com\\itheima\\hello\\缓冲流\\itheima.txt"));
            BufferedWriter bw = new BufferedWriter(new FileWriter("helloworld-app\\src\\com\\itheima\\hello\\缓冲流\\itheima02out.txt",true));
            )
            {
                List<String> data = new ArrayList<>();
                String line;
                while ((line=br.readLine())!=null){
                    data.add(line);
                }
                Collections.sort(data);//排序
                System.out.println(data);//打印
                for (String d : data) {
                    bw.write(d);//写入到新的文件
                    bw.newLine();

                }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
